﻿

@{
    ViewBag.Title = "Log";
}
<style type="text/css">
    .pull-left.pagination-detail {
        display: none;
    }
</style>
<link href="~/assets/js/bootstrap-table/bootstrap-table.min.css" rel="stylesheet" />


<div class="page-body">
    <div id="serch-form" class="form-inline">
        <a href="@Url.Action("ClearLog")" class="btn btn-danger">清理日志</a>
        <div class="pull-right">
            <div class="form-group">
                <span class="input-icon icon-right">
                    <input type="text" class="form-control date-picker" value="@DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd")" name="StartDate" id="StartDate" placeholder="开始时间">
                    <i class="fa fa-calendar"></i>
                </span>
            </div>
            -
            <div class="form-group">
                <span class="input-icon icon-right">
                    <input type="text" class="form-control" value="@DateTime.Now.AddDays(1).ToString("yyyy-MM-dd")" name="EndDate" id="EndDate" placeholder="结束时间">
                    <i class="fa fa-calendar"></i>
                </span>
            </div>
            <div class="form-group">
                <select class="form-control" id="Category">
                    <option value="0">全部类型</option>
                    <option value="1">信息</option>
                    <option value="2">警告</option>
                    <option value="3">异常</option>
                </select>
            </div>
            <div class="input-group">
                <span class="input-group-btn">
                    <button class="btn btn-default" type="button" id="btn_table_search" onclick="grid.reload();"><i class="fa fa-search blue"></i></button>
                </span>
            </div>
        </div>
    </div>
    <table id="table" class="mychar1-table"></table>
</div>


@section scripts{
    <script src="~/assets/js/bootstrap-table/bootstrap-table.min.js"></script>
    <script src="~/assets/js/bootstrap-table/bootstrap-table-zh-CN.min.js"></script>
    <script src="~/assets/js/laydate5.0.9/laydate.js"></script>
    <script src="~/assets/js/bootbox/bootbox.js"></script>

    <script>
        hos.ui.util.breadCrumb("系统日志");
        var startTime = laydate.render({
            elem: '#StartDate', type: 'date', done: function (value, date, endDate) {
                date.month = date.month - 1;
                endTime.config.min = date;
                $(endTime.config.elem).focus();
            }
        });
        var endTime = laydate.render({
            elem: '#EndDate', type: 'date', done: function (value, date, endDate) {
                date.month = date.month - 1;
                startTime.config.max = date;
            }
        });
        var grid = hos.ui.ctrl.gridView("table", {
            url: '/System/QueryLogPager',
            columns: [
                { field: 'Node', title: '节点', align: 'center', width: '8', widthUnit: '%' },
                { field: 'Category', title: '类型', align: 'center', width: '8', widthUnit: '%', formatter: function (value, row, index) {
                    var text = '';
                    switch (value) {
                        case 1:
                            text = '<label style="color:#38b03f">信息</label>';
                            break;
                        case 2:
                            text = '<label style="color:#f1a325">警告</label>';
                            break;
                        case 3:
                            text = '<label style="color:red">异常</label>';
                            break;
                    }
                    return text;
                }
                },
                { field: 'CreateTime', title: '生成时间', align: 'center', width: '12', widthUnit: '%' },
                {
                    field: 'Message', title: '内容', width: '80', widthUnit: '%', formatter: function (value, row, index) {
                        var text = value;
                        if (row.Category == 3) {
                            text += '     <a class="label label-danger graded" onclick="showStackTrace(' + index + ')">查看堆栈</a>';
                        }
                        return text;
                    }
                }
            ]
        });
        $('#btn_clear').on("click", function () {
            var params = {
                task: $("#Task").val(),
                category: $("#Category").val(),
            };
            hos.ui.util.postJson("@Url.Action("ClearLog")", params)
        })

        function showStackTrace(index) {
            bootbox.dialog({
                message: "<xmp style='overflow: auto;'>"+grid.getData(index).StackTrace+"</xmp>",
                title: "堆栈信息",
                size: "lg"
            });
        }
    </script>
}

